<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>    
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/common/head.jsp" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<body>
	<div>
		
			<label>用户名：<input id="username" type="text" /></label><br/>
			<label>密码：<input  id="password" type="password" /></label><br/>
			<label>
			<input id="verifyCode" type="text" size="10px;"/>
				<img id="cjpge" alt="看不清楚" src="${ctx}/secure/cjpge.jpg" alt="点击更新验证码" title="点击更新验证码" onclick="$.login.imgClick();"/>
			</label><br/>
			<input type="button"  id="login" value="登录">
	</div>
</body>
<script type="text/javascript">
;(function($){ 
	$.login={
		imgClick:function(){
			$("#cjpge").attr("src","${ctx}/secure/cjpge.jpg?d="+new Date().getTime());
		},
		login:function (){	
		  debugger;
		  var u = $("#username").val();
		  var p = $("#password").val();
		  var c=$("#verifyCode").val();
		  debugger;
		  p =CryptoJS.MD5(CryptoJS.MD5(CryptoJS.MD5(p)+u)+c)+""; //转码
	      $("#username").val('');
          $("#password").val('');
// 		  $("#message").html('');
		  $("#verifyCode").val('');
		  $.ajax({
		   			type:"POST",
		   			url:"${ctx}/secure/login.do",
		   			data:{"username":u,"password":p,"verifyCode":c},
		   			dataType:"json",
		   			async: false,
		   			success:function(data)
		   			{
		   				if (null != data) 
		   				{	
		   					debugger;
		   					if (data.msg==true) 
		   					{
		   					window.location.href = "${ctx}/main.htm";	
							} else if (data.flag == 'b'){
								$("#message").html("用户名或密码不正确");
								 var verifyObj = document.getElementById("Verify");
						    	 //刷新验证码
							    verifyObj.src="<%=request.getContextPath() %>/sys/securityCodeImage!codeImage.action?timestamp="+new Date().getTime();
							} else if(data.flag== 'c'){
								$("#message").html("验证码不能为空");
							}else if(data.flag=='d'){
								$("#message").html("验证码不正确");
							}
						}
					}
				});
		} 
	}
})(jQuery);

$(function(){
   	//用户登录
	$("#login").bind('click',function(){
		$.login.login();
	});	
});
</script>
</html>